#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
【需求背景】
b2b 有手机号有nameId的新增条数，确定是否全已经入库，未入库的导出
'''

import sys

sys.path.append('/mnt/moonbrook/Moonbrook')
from aes import contact_aes, name_aes
import os
import re
import json
import time
import requests
from copy import deepcopy
from datetime import datetime, timedelta
from apscheduler.schedulers.blocking import BlockingScheduler

from base import ExportAndTjBase
from models import MongoQueryConfig, RobotConfig
from utils import Utils
from robot import DingtalkRobot

reload(sys)
sys.setdefaultencoding('utf-8')


class ExportAndTj(ExportAndTjBase):
    week_min, week_max = Utils.get_date_range(ndays=7)


    def __init__(self, *args, **kwargs):
        super(ExportAndTj, self).__init__(*args, **kwargs)
        # todo other col

    def get_data_from_mongo(self, config, save_result_dic=None):
        records_crusor = self.get_records_crusor(config)
        save_result_dic['no_nameId_count'] = records_crusor.count()
        self.log('get_data_from_mongo over ')
        self.save_tj_info(save_result_dic)
        return save_result_dic



    def run(self):
        # 需要统计的维度
        save_result_dic = {
            'no_nameId_count':0,
        }
        # 查询mongo的配置，这些配置写在一起主要是为了借鉴起来方便
        week_min, week_max = Utils.get_date_range(ndays=7,end_time="2021-11-22")
        config = MongoQueryConfig.dsf_s24_tj_config(week_min,week_max)
        result_dic = self.get_data_from_mongo(config, save_result_dic)


def run(file_name):
    # py文件名/file_name+小时时间
    abs_file_name = Utils.generate_abs_path(file_name, current_py_path=__file__)
    export_and_tj = ExportAndTj(abs_file_name)
    export_and_tj.main()


def scheduler_run(file_name):
    # py文件名/file_name+小时时间
    abs_file_name = Utils.generate_abs_path(file_name, current_py_path=__file__)
    scheduler = BlockingScheduler()
    scheduler.add_job(func=run, trigger='cron',
                      args=(abs_file_name,),
                      # day_of_week="sun",
                      hour='20', minute='52', id='dd_run')
    scheduler.start()


if __name__ == '__main__':
    file_name = 'b2b未映射数据统计'
    run(file_name)
    # scheduler_run(file_name)
